import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;
 
public class Demo6726 {

	public static void main(String[] args) {

		// 使用自然排序
		List<Course6726> courses = getCourses();
		for (Course6726 c : courses) {
			System.out.println(c);
		}
		
		// 按compareTo方法进行自然排序
		System.out.println("==========按成绩降序==========");
		TreeSet<Course6726> courseSet1 = new TreeSet<>();
		addSet(courseSet1);
		courseSet1.forEach(System.out::println);
		// 按学期升序
		sorterByTerm6726();
	}
	private static List<Course6726> getCourses()  {
		// 使用数组保存一组对象
		 List<Course6726> courses=new ArrayList<Course6726>();
		 courses.add(new Course6726("A001", "C程序设计基础", "1上", 4, 80));
		 courses.add(new Course6726("B002", "Pthon程序基础", "1下", 2, 85));
		 courses.add(new Course6726("A002", "面向对象程序设计", "2上", 3, 78));
		 courses.add( new Course6726("C001", "Java程序高级开发", "3上", 2, 83));
		 courses.add(new Course6726("C002", "软件工程与UML", "3下", 3, 75));
		 courses.add( new Course6726("B001", "操作系统", "2下", 3, 90));
		 courses.add( new Course6726("A003", "数据库原理", "2上", 3, 78));
		 courses.add( new Course6726("B003", "网络基础", "3上", 3, 75));
		 courses.add(new Course6726("0001", "大学英语", "1上", 3, 80));
		 courses.add( new Course6726("0002", "高等数学", "1下", 2, 85));
		return courses;
	}
	private static void addSet(TreeSet<Course6726> courseSet) {
		courseSet.add(new Course6726("0001", "大学英语\t\t", "1上", 3, 80));
		courseSet.add(new Course6726("0002", "高等数学\t\t", "1下", 2, 85));
		courseSet.add(new Course6726("A001", "C程序设计基础\t\t", "1上", 4, 80));
		courseSet.add(new Course6726("A002", "面向对象程序设计\t", "2上", 3, 78));
		courseSet.add(new Course6726("A003", "数据库原理\t\t", "2上", 3, 78));
		courseSet.add(new Course6726("B001", "操作系统\t\t", "2下", 3, 90));
		courseSet.add(new Course6726("B002", "Python程序基础\t", "1下", 2, 85));
		courseSet.add(new Course6726("B003", "网络基础\t\t", "3上", 3, 75));
		courseSet.add(new Course6726("C001", "Java程序高级开发\t", "3上", 2, 83));
		courseSet.add(new Course6726("C002", "软件工程与UML\t\t", "3下", 3, 75));
	
	}
	
	private static void sorterByTerm6726() {
		System.out.println("==========按学期升序 ==========");
		// Lambda表达式传递Comparator函数式接口 与SorterByTerm类要求相等
		// 如果开课学期相等调用Course可以直接调用compareTo方法进行进行成绩降序、学分升序、课程号降序排序
		// Lambda表达式只有一行可以省略{}与return
		TreeSet<Course6726> courseSet3 = new TreeSet<>((c1, c2) -> c1.getTerm()
				.compareTo(c2.getTerm()) == 0 ? c1.compareTo(c2) : c1.getTerm()
				.compareTo(c2.getTerm()));
		// 添加数据
		addSet(courseSet3);
		// 方法引用输出集合中的元素
		courseSet3.forEach(System.out::println);
	}
		
}